{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "491cbd2d-1199-4d99-ab82-b78a312d39da",
   "metadata": {},
   "source": [
    "### Try this notebook in Google Colab, Binder or SageMaker!\n",
    "\n",
    "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/InsightSoftwareConsortium/itkwidgets/blob/main/examples/integrations/vtk/vtkPolyDataPointSet.ipynb)\n",
    "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/InsightSoftwareConsortium/itkwidgets/HEAD?labpath=examples%2Fintegrations%2Fvtk%2FvtkPolyDataPointSet.ipynb)\n",
    "[![Open In SageMaker Studio Lab](https://studiolab.sagemaker.aws/studiolab.svg)](https://studiolab.sagemaker.aws/import/github.com/InsightSoftwareConsortium/itkwidgets/blob/main/examples/integrations/vtk/vtkPolyDataPointSet.ipynb)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5bc1116d-ac15-4904-b1b6-e380def34369",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Install dependencies for this example\n",
    "import sys\n",
    "\n",
    "!{sys.executable} -m pip install -q vtk \"itkwidgets[all]>=1.0a23\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "cde79357-38d8-4da0-b73b-eef96cc01f14",
   "metadata": {},
   "outputs": [],
   "source": [
    "from urllib.request import urlretrieve\n",
    "import os\n",
    "\n",
    "import vtk\n",
    "\n",
    "from itkwidgets import view"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7ea3eb03-26d7-44af-a383-0ce5fd2d2859",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Download data\n",
    "file_name = 'cow.vtp'\n",
    "if not os.path.exists(file_name):\n",
    "    url = 'https://data.kitware.com/api/v1/file/5a826bdb8d777f0685782957/download'\n",
    "    urlretrieve(url, file_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1c91d7cc-7b31-4555-890a-5b91315f5268",
   "metadata": {},
   "outputs": [],
   "source": [
    "reader = vtk.vtkXMLPolyDataReader()\n",
    "reader.SetFileName(file_name)\n",
    "reader.Update()\n",
    "vtk_poly = reader.GetOutput()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1c5c6c98-5463-4e62-a325-46dcc445c79c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "                <img id=screenshot_imjoy_window_c1087951-1c4f-4baf-883c-da28e2695f00 src=>\n",
       "                <script id=\"script_imjoy_window_c1087951-1c4f-4baf-883c-da28e2695f00\" type=\"text/javascript\">\n",
       "                    var container = document.getElementById(\"script_imjoy_window_c1087951-1c4f-4baf-883c-da28e2695f00\").parentNode;\n",
       "                    var image = document.getElementById(\"screenshot_imjoy_window_c1087951-1c4f-4baf-883c-da28e2695f00\");\n",
       "                    if (!image) {\n",
       "                        image = document.createElement(\"img\");\n",
       "                        image.id = \"screenshot_imjoy_window_c1087951-1c4f-4baf-883c-da28e2695f00\";\n",
       "                        container.appendChild(image);\n",
       "                    }\n",
       "                    image.src = \"\";\n",
       "                    var viewer = document.getElementById(\"imjoy_window_c1087951-1c4f-4baf-883c-da28e2695f00\");\n",
       "                    // Hide the static image if the Viewer is visible\n",
       "                    image.style.display = viewer ? \"none\" : \"block\";\n",
       "                </script>\n",
       "            "
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "window.connectPlugin && window.connectPlugin(\"6e16aade-7970-4066-ad06-8cceaa10c014\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div id=\"5aa2cc0a-6e53-423b-a1da-9319c720c85b\"></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<itkwidgets.viewer.Viewer at 0x7fd07f13c6d0>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "view(point_set=vtk_poly)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
